package main

import (
	"github.com/labstack/echo/v4"
	"github.com/labstack/echo/v4/middleware"
	"net/http"
)

// Add trailing slash 中间件会在在请求的 URI 后加上反斜杠
func main() {

	e := echo.New()
	//用法一
	//e.Pre(middleware.AddTrailingSlash())

	//用法二：
	e.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{
		RedirectCode: http.StatusMovedPermanently,
	}))

	e.Use(middleware.Logger())
	e.Use(middleware.RequestID())
	e.GET("/index/", Index)

	e.Start(":80")

}

func Index(c echo.Context) error {
	requestId := c.Response().Header().Get(echo.HeaderXRequestID)
	return c.String(200, requestId)
}
